<?php

namespace App\Common\Trait;

trait InstanceTrait
{
    private static $instances = [];

    /**
     * 快速创建单例实例
     * @return mixed|static
     * @author 我只想看看蓝天 <1207032539@qq.com>
     */
    public static function singleInstance()
    {
        $key = get_called_class();
        if (empty(self::$instances[$key])) {
            self::$instances[$key] = new static();
        }
        return self::$instances[$key];
    }

    /**
     * 快速创建新的实例
     * @return static
     * @author 我只想看看蓝天 <1207032539@qq.com>
     */
    public static function newInstance()
    {
        return new static();
    }
}
